<!--
 * @Author: xuzehan 123@qq.com
 * @Date: 2023-04-10 18:28:38
 * @LastEditors: xuzehan 935351619@qq.com
 * @LastEditTime: 2024-05-11 12:43:17
 * @FilePath: \ant-design-vue-jeecg-master\src\views\situationDisplay\modules\SXZY.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <div class="windowInfo windowInfo1">
      <img
        src="../../../../public/hide1.png"
        alt
        @click="hideBox"
        style="width: 20px; position: absolute; right: 10px; z-index: 2; cursor: pointer"
      />
      <div class="showBox">
        <h3 style="margin-left: 5px; ">资源状态显示</h3>
        <div class="windowInfo-body">
          <div class="ZY-box">
            <h3>
              <span style="margin-right:19px">时隙资源使用情况</span>
              <span  id="spanBox"></span>
            </h3>

            <div class="tableContainer">
              <div v-for="item in 5" class="tableBox" :key="item+'car'">
                <span v-for="item in 6" :key="item+'time'"></span>
              </div>
            </div>
          </div>
          <a-divider />
          <div class="ZY-box">
            <h3>
              信道资源使用情况
              <!-- <span class="emptyTag">未占用</span>
              <span class="employTag">占用</span>-->
            </h3>
            <a-descriptions size="small" style="width:390px">
              <a-descriptions-item label="本振编号">{{form.localOscillator?form.localOscillator:"*"}}</a-descriptions-item>
              <a-descriptions-item label="中心频点">{{form.cfp?form.cfp:"*"}}MHz</a-descriptions-item>
            </a-descriptions>
            <!-- <div class="tableContainer tableContainer1">
              <a-popover title="占用信息"
                        overlayClassName="poperLayTable"
                        :key="index + 'PDSolt'"
                          v-for="(item, index) in statusList1">
                <template slot="content">
                  <p>占用车:{{item.identificationCode}}</p>
                  <p>占用弹:{{item.missileIdentificationCode}}</p>
                  <p>中频号:{{item.intermediateFrequency}}</p>
                </template>
                <div class="employ">
                  {{item.digitalFilter}}
               </div>
              </a-popover>
            </div> -->
            <div class='tableBoxDiv'>
               <a-table size="small" :scroll="{y: 150 }" :columns="columns" :data-source="data" :pagination="false" bordered></a-table>

            </div>

          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import $ from 'jquery'
import { getAction } from '@/api/manage'
import { mapGetters } from 'vuex'

export default {
  computed: {
    ...mapGetters(['websocketMsg']),
    websocketMsg() {
      return this.$store.state.user.websocketMsg
    },
  },

  watch: {
    websocketMsg: {
      handler(val) {
        let msg = JSON.parse(val)
        if (msg.cmd == 'HOME_REFRESH') {
          this.getList()
        }
      },
    },
  },
  data() {
    return {
      form: {},
      data:[],
      columns:[
            {
          title: '指挥车',
          dataIndex: 'identificationCode',
          key: 'identificationCode',
          width:100,
           customRender: (value, row, index) => {
             if(value){
                    const obj = {
                    children: value,
                    attrs: {},
                  }
                  obj.attrs.rowSpan = row.identificationCoderowSpan
                  return obj
            }else{
              return '/'
            }
          },
        },

          {
          title: '占用中频',
          dataIndex: 'intermediateFrequency',
          key: 'intermediateFrequency',
          width:120,

         },
        {
          title: '信道号',
          dataIndex: 'digitalFilter',
          key: 'digitalFilter',
          width:100,
         },

         {
          title: '占用弹',
          dataIndex: 'missileIdentificationCode',
          key: 'missileIdentificationCode',
          customRender: function (text) {
            if(text){
              return text
            }else{
              return '/'
            }
          },
         },

      ],
      localOscillatorList: [
        { label: '0', value: '0', cfp: '5540' },
        { label: '1', value: '1', cfp: '5560' },
        { label: '2', value: '2', cfp: '5580' },
        { label: '3', value: '3', cfp: '5600' },
        { label: '4', value: '4', cfp: '5620' },
        { label: '5', value: '5', cfp: '5640' },
        { label: '6', value: '6', cfp: '5660' },
        { label: '7', value: '7', cfp: '5680' },
        { label: '8', value: '8', cfp: '5700' },
        { label: '9', value: '9', cfp: '5720' },
        { label: '10', value: 'A', cfp: '5740' },
        { label: '11', value: 'B', cfp: '5760' },
        { label: '12', value: 'C', cfp: '5780' },
        { label: '13', value: 'D', cfp: '5800' },
        { label: '14', value: 'E', cfp: '5820' },
      ],
      statusList: [],
      colorList: ['#f51616', '#e0f17a', ' #f57dab', 'rgb(123, 243, 93)'],
      tagList: ['redTag', 'yellowTag', 'pinkTag', 'employTag'],
      statusList1: [],
      legendList: [
        // { identificationCode: "2100", slot: [0, 1] },
        // { identificationCode: "2200", slot: [2] },
        // { identificationCode: "2300", slot: [3] },
        // { identificationCode: "2400", slot: [4] },
      ],
      url: {
        getLocalOscillatorInfo: "/telemetryInfo/nmcTelemetryInfo/getLocalOscillatorInfo",
        getResourceOccupancy: '/commandVehicle/nmcCommandVehicle/getByCurrentDayOfCommandVehicleResourceUsageExcludeRetired'
      }
    }
  },
  created() {

    this.init()
  },
  mounted() {

    this.getList()

  },
  methods: {
     changeData(data, field) {
      let count = 0 //重复项的第一项
      let indexCount = 1 //下一项
      while (indexCount < data.length) {
        var item = data.slice(count, count + 1)[0] //获取没有比较的第一个对象
        if (!item[`${field}rowSpan`]) {
          item[`${field}rowSpan`] = 1 //初始化为1
        }
        if (item[field] === data[indexCount][field]) {
          //第一个对象与后面的对象相比，有相同项就累加，并且后面相同项设置为0
          item[`${field}rowSpan`]++
          data[indexCount][`${field}rowSpan`] = 0
        } else {
          count = indexCount
        }
        indexCount++
      }
      return data
    },
    getList() {
      getAction(this.url.getResourceOccupancy).then(res => {
        if (res.success) {
          this.legendList=[]
          this.statusList1=[]
          this.data=[]
          let data = res.result
          this.legendList = data.slotUsageInfoList
          this.statusList1 = data.digitalFilterUsageInfoList
          this.data=data.digitalFilterUsageInfoList
          this.initPseudoClasses()
          let propsList = ['identificationCode','intermediateFrequency']
            propsList.map((item) => {
              this.data = [...this.changeData(this.data, item)]
            })
          console.log(data,'=========');
        } else {
          this.$message.error(res.message)
        }
      })

      getAction(this.url.getLocalOscillatorInfo).then(res => {
        if (res.success) {
          this.form.localOscillator = res.result
          this.form.cfp = this.localOscillatorList.find(i => i.value == res.result).cfp
        } else {
          this.$message.error(res.message)
        }
      })

    },
    initPseudoClasses() {
      let div = document.getElementById('spanBox')
      div.innerHTML=''
      const arr = Array.from(document.getElementsByClassName('tableBox'))
      arr.forEach(i=>{
        i.style.background = 'transparent'
      })
      let { colorList, tagList } = this
      this.legendList.forEach((i, index) => {
        let newSpan = document.createElement('span')
        newSpan.innerHTML = i.identificationCode
        newSpan.style.marginRight = '8px'
        //添加伪类元素---
        var style = document.createElement("style");
        style.type = "text/css";
        let css = `.${tagList[index]}:before{content:'';margin-right: 5px;border: 0.1px solid #7e7c7c;width: 12px;height: 12px;display: inline-block;background: ${colorList[index]};}`
        style.appendChild(document.createTextNode(css))
        newSpan.appendChild(style)
        //添加伪类元素---
        newSpan.setAttribute("class", tagList[index])
        div.appendChild(newSpan)
        // i.bgColor = colorList[index]
        console.log(i, 'index')
        i.usageSlot.forEach(j => {
          document.getElementsByClassName('tableBox')[Number(j) + 1].style.background = colorList[index]
        })
      })
    },
    hideBox() {
      $('.showBox').fadeToggle(1000)
    },
    init() {
      for (let i = 0; i < 128; i++) {
        this.statusList1.push({ status: Math.round(Math.random()), index: i })
      }
      // this.statusList1 = this.statusList1.filter(i => i.status == 1)
    },
  },
}
</script>

<style lang="less" scoped>
.tableBoxDiv {
  .ant-table-header {
    background: transparent !important;
  }

  .ant-table .ant-table-thead>tr>th {
    background: transparent !important;
  }
}
.ant-table-thead {
  background: rgba(30, 36, 50, 0) !important;
}
.windowInfo  .ant-table {
  .windowInfo .ant-table-thead > tr > th {
    color: #fff;
    background: rgba(30, 36, 50, 0) !important;
  }
  .windowInfo .ant-table-thead > td {
    color: #fff;
  }
}
.windowInfo .ant-table-wrapper {
  color: #fff;
  background: rgba(30, 36, 50, 0) !important;
}
.windowInfo ,
.windowInfo  .ant-card-head,
.windowInfo  .ant-card-body {
  background: rgba(30, 36, 50, 0) !important;
}
.tableContainer {
  width: 380px;
  max-height: 170px;
  overflow: auto;
  display: flex;
  // border: solid 0.1px rgb(87, 217, 249);
  flex-wrap: wrap;
  margin: 0 auto;
  padding: 1px;
  .tableBox {
    box-sizing: border-box;
    // min-width
    // height: 12px;
    // border: solid 0.1px rgb(148, 148, 148);
    span {
      box-sizing: border-box;
      width: 12px;
      height: 12px;
      border: solid 0.1px rgb(148, 148, 148);
    }
  }
  .tableItem {
    width: 12px;
    height: 12px;
    text-align: center;
    line-height: 12px;
    border: solid 0.1px rgb(148, 148, 148);
    // border: solid 0.1px rgb(87, 217, 249);
  }
  .tableItem1 {
    width: 30px;
    height: 30px;
    text-align: center;
    line-height: 30px;
    border: solid 0.1px rgb(148, 148, 148);
    // border: solid 0.1px rgb(87, 217, 249);
  }
}
.red {
  background-color: #f51616;
}
.redTag::before {
  content: '';
  display: inline-block;
  height: 12px;
  width: 12px;
  border: 0.1px solid #7e7c7c;
  margin-right: 5px;
  background: #f51616;
}
.pink {
  background-color: #f57dab;
}
.pinkTag::before {
  content: '';
  display: inline-block;
  height: 12px;
  width: 12px;
  border: 0.1px solid #7e7c7c;
  margin-right: 5px;
  background: #f57dab;
}
.yellow {
  background-color: #e0f17a;
}
.yellowTag::before {
  content: '';
  display: inline-block;
  height: 12px;
  width: 12px;
  border: 0.1px solid #7e7c7c;
  margin-right: 5px;
  background: #e0f17a;
}
.redTag,
.pinkTag,
.yellowTag,
.employTag,
.emptyTag {
  float: right;
  font-size: 14px;
  line-height: 30px;
  margin-right: 5px;
}
.employTag::before {
  content: '';
  display: inline-block;
  height: 12px;
  width: 12px;
  border: 0.1px solid #7e7c7c;
  margin-right: 5px;
  background: rgb(123, 243, 93);
}

.employ {
  width: 30px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  box-sizing: border-box;
  border: 0.1px solid #7e7c7c;
  background-size: 50px 50px;
  background-color: rgb(123, 243, 93);
  background-image: -webkit-linear-gradient(
    -45deg,
    rgba(133, 201, 56, 0.2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(139, 248, 96, 0.2) 50%,
    rgba(116, 115, 115, 0.2) 75%,
    transparent 75%,
    transparent
  );
  background-image: linear-gradient(
    -45deg,
    rgba(107, 106, 106, 0.2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(134, 132, 132, 0.2) 50%,
    rgba(117, 116, 116, 0.2) 75%,
    transparent 75%,
    transparent
  );
}
.windowInfo {
  position: relative;
  min-width: 40px;
  min-height: 40px;
  h3 {
    color: #fff;
    // color: rgb(87, 217, 249);
  }
  color: #fff;
  padding: 10px;
  background: rgba(30, 36, 50, 0.6) !important;
}
.emptyTag::before {
  display: inline-block;
  content: '';
  height: 12px;
  width: 12px;
  margin-right: 5px;
  border: 0.1px solid #7e7c7c;
  background: #fff;
}
.empty {
  background-size: 50px 50px;
  background-color: #fff;
  // background-color: rgb(68, 69, 70);
  background-image: -webkit-linear-gradient(
    -45deg,
    rgba(255, 255, 255, 0.2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(116, 115, 115, 0.2) 75%,
    transparent 75%,
    transparent
  );
  background-image: linear-gradient(
    -45deg,
    rgba(107, 106, 106, 0.2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(134, 132, 132, 0.2) 50%,
    rgba(117, 116, 116, 0.2) 75%,
    transparent 75%,
    transparent
  );
}
/* 四角边框--start */
.windowInfo {
  position: relative;
  // width: 300px;
  // /* height: 300px; */
  // margin: 300px auto;
  // /* background: rgba(1, 19, 67, 0.8); */

  border: 2px solid #58d0f3 !important;
  z-index: 1;
  .ZY-box {
    padding: 5px;
  }
}

.windowInfo::before {
  position: absolute;
  content: '';
  top: -2px;
  bottom: -2px;
  left: 30px;
  width: calc(100% - 60px);
  /* border-top: 2px solid #016886; */
  /* border-bottom: 2px solid #016886; */
  border-bottom: 2px solid #4f78ae;
  border-top: 2px solid #4f78ae;
  z-index: -1;
}
.windowInfo::after {
  position: absolute;
  content: '';
  top: 30px;
  right: -2px;
  left: -2px;
  height: calc(100% - 60px);
  border-right: 2px solid #4f78ae;
  border-left: 2px solid #4f78ae;
  z-index: -1;
}

/* 四角边框--end */
</style>
<style >
.windowInfo .ant-descriptions-title,
.windowInfo .ant-descriptions-item-label,
.windowInfo .ant-descriptions-item-content {
  font-size: 16px;
}
   /* .ant-table-tbody tr td{
    white-space: break-spaces;
   } */
</style>
